// importM
import 'package:flutter/material.dart';
// ignore: unused_import
import './MyIcon.dart';
import 'res/listData.dart';

void main() {
  runApp(
    MaterialApp(
      home: Scaffold(
        // 顶部导航
        appBar: AppBar(
          title: Text("FlutterList"),
          backgroundColor: Colors.deepPurple,
        ),
        body: ListList2(),
      ),
    ),
  );
}

// List列表
class MyIcon extends StatelessWidget {
  const MyIcon({super.key});

  @override
  Widget build(BuildContext context) {
    return ListView(
      children: const <Widget>[
        ListTile(
          leading: Icon(Icons.home),
          title: Text("主页"),
          trailing: Icon(Icons.chevron_right),
        ),
        Divider(),
        ListTile(
          leading: Icon(Icons.assignment),
          title: Text("订单"),
          trailing: Icon(Icons.chevron_right),
        ),
        Divider(),
      ],
    );
  }
}

// List列表
// ignore: camel_case_types
class news extends StatelessWidget {
  const news({super.key});

  @override
  Widget build(BuildContext context) {
    return ListView(
      padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
      children: <Widget>[
        ListTile(
          leading: Image.network(
            "https://img-s.msn.cn/tenant/amp/entityid/AA1LbsBs.img?w=768&h=327&m=6",
          ),
          title: Text("微信悄悄上线AI播客，“真人”唠嗑给你讲新闻"),
        ),
        Divider(),
        ListTile(
          title: Text("AI重塑新闻版图：人类编辑与AI共舞的新时代"),
          trailing: Image.network(
            "https://img-s.msn.cn/tenant/amp/entityid/AA1L8o2z.img?w=400&h=300&m=6",
          ),
        ),
        Divider(),
        ListTile(
          leading: Image.network(
            "https://img-s.msn.cn/tenant/amp/entityid/AA1Lcm9i.img?w=400&h=300&m=6",
          ),
          title: Text("微信AI播客新功能：双主播对话形式，让新闻更“动听”"),
        ),
        Divider(),
      ],
    );
  }
}

class ListImg extends StatelessWidget {
  const ListImg({super.key});

  @override
  Widget build(BuildContext context) {
    return ListView(
      padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
      children: <Widget>[
        Image.network("https://www.itying.com/images/flutter/1.png"),
        Container(
          margin: EdgeInsets.fromLTRB(0, 5, 0, 10),
          height: 44,
          child: Text(
            "I am Flutter Title",
            textAlign: TextAlign.center,
            style: TextStyle(fontSize: 22),
          ),
        ),
        Image.network("https://www.itying.com/images/flutter/2.png"),
        Container(
          margin: EdgeInsets.fromLTRB(0, 5, 0, 10),
          height: 44,
          child: Text(
            "I am Flutter Title",
            textAlign: TextAlign.center,
            style: TextStyle(fontSize: 22),
          ),
        ),
        Image.network("https://www.itying.com/images/flutter/3.png"),
        Container(
          margin: EdgeInsets.fromLTRB(0, 5, 0, 10),
          height: 44,
          child: Text(
            "I am Flutter Title",
            textAlign: TextAlign.center,
            style: TextStyle(fontSize: 22),
          ),
        ),
        Image.network("https://www.itying.com/images/flutter/4.png"),
        Container(
          margin: EdgeInsets.fromLTRB(0, 5, 0, 10),
          height: 44,
          child: Text(
            "I am Flutter Title",
            textAlign: TextAlign.center,
            style: TextStyle(fontSize: 22),
          ),
        ),
        Image.network("https://www.itying.com/images/flutter/5.png"),
        Container(
          margin: EdgeInsets.fromLTRB(0, 5, 0, 10),
          height: 44,
          child: Text(
            "I am Flutter Title",
            textAlign: TextAlign.center,
            style: TextStyle(fontSize: 22),
          ),
        ),
        Image.network("https://www.itying.com/images/flutter/6.png"),
        Container(
          margin: EdgeInsets.fromLTRB(0, 5, 0, 10),
          height: 44,
          child: Text(
            "I am Flutter Title",
            textAlign: TextAlign.center,
            style: TextStyle(fontSize: 22),
          ),
        ),
        Image.network("https://www.itying.com/images/flutter/7.png"),
        Container(
          margin: EdgeInsets.fromLTRB(0, 5, 0, 10),
          height: 44,
          child: Text(
            "I am Flutter Title",
            textAlign: TextAlign.center,
            style: TextStyle(fontSize: 22),
          ),
        ),
      ],
    );
  }
}

// 横向列表
class ListGoods extends StatelessWidget {
  const ListGoods({super.key});

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: 2000,
      child: ListView(
        scrollDirection: Axis.horizontal,
        padding: EdgeInsets.all(5),
        children: <Widget>[
          Container(
            width: 150,
            padding: EdgeInsets.fromLTRB(0, 0, 5, 0),
            child: Column(
              children: [
                Image.network(
                  "https://www.itying.com/images/flutter/1.png",
                  fit: BoxFit.cover,
                ),
                Text("￥ 1000", style: TextStyle(fontSize: 22)),
              ],
            ),
          ),
          Container(
            width: 150,
            padding: EdgeInsets.fromLTRB(0, 0, 5, 0),
            child: Column(
              children: [
                Image.network(
                  "https://www.itying.com/images/flutter/2.png",
                  fit: BoxFit.cover,
                ),
                Text("￥ 1000", style: TextStyle(fontSize: 22)),
              ],
            ),
          ),
          Container(
            width: 150,
            padding: EdgeInsets.fromLTRB(0, 0, 5, 0),
            child: Column(
              children: [
                Image.network(
                  "https://www.itying.com/images/flutter/3.png",
                  fit: BoxFit.cover,
                ),
                Text("￥ 1000", style: TextStyle(fontSize: 22)),
              ],
            ),
          ),
          Container(
            width: 150,
            padding: EdgeInsets.fromLTRB(0, 0, 5, 0),
            child: Column(
              children: [
                Image.network(
                  "https://www.itying.com/images/flutter/4.png",
                  fit: BoxFit.cover,
                ),
                Text("￥ 1000", style: TextStyle(fontSize: 22)),
              ],
            ),
          ),
          Container(
            width: 150,
            padding: EdgeInsets.fromLTRB(0, 0, 5, 0),
            child: Column(
              children: [
                Image.network(
                  "https://www.itying.com/images/flutter/5.png",
                  fit: BoxFit.cover,
                ),
                Text("￥ 1000", style: TextStyle(fontSize: 22)),
              ],
            ),
          ),
          Container(
            width: 150,
            padding: EdgeInsets.fromLTRB(0, 0, 5, 0),
            child: Column(
              children: [
                Image.network(
                  "https://www.itying.com/images/flutter/6.png",
                  fit: BoxFit.cover,
                ),
                Text("￥ 1000", style: TextStyle(fontSize: 22)),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

// 动态列表
class ListList extends StatelessWidget {
  const ListList({super.key});

  List<Widget> _initList() {
    var res = listData.map((element) {
      return ListTile(
        title: Text("耳机: ${element["earName"]}"),
        subtitle: Column(
          crossAxisAlignment: CrossAxisAlignment.start, // 左对齐
          children: [
            Text("SN码: ${element["snCode"]}"),
            Text("生成时间: ${element["createTime"]}"),
            Text("ID: ${element["snId"]}"),
          ],
        ),
      );
    }).toList();
    return res;
  }

  @override
  Widget build(BuildContext context) {
    return ListView(children: _initList());
  }
}

// 使用ListBulider
class ListList2 extends StatelessWidget {
  const ListList2({super.key});

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemCount: listData.length,
      itemBuilder: (context, index) {
        return ListTile(
          title: Text("耳机: ${listData[index]["earName"]}"),
          subtitle: Column(
            crossAxisAlignment: CrossAxisAlignment.start, // 左对齐
            children: [
              Text("SN码: ${listData[index]["snCode"]}"),
              Text("生成时间: ${listData[index]["createTime"]}"),
              Text("ID: ${listData[index]["snId"]}"),
            ],
          ),
        );
      },
    );
  }
}
